<template>
	<view class="mainpadding ">
		<!--  无地址-->
		<view class="" v-if="!addressList.length">
			<view class="flexcenter">
				<image style="width: 484rpx; height: 357rpx;" src="../static/image/system/kdz.png" mode=""></image>
			</view>
			<view class="titletext xiaohei margin_top6 textcenter">您还没有添加过地址</view>
			<view class="strongtext xiaohui margin_top2 textcenter">添加地址信息，让您的操作更便捷</view>
		</view>
		<view class="xiahuaxian sahngbj" v-for="item in addressList" :key="item.id" @click="checkaddress(item.id)">
			<view class="ershiba xiaohei">{{item.cityinfo}}{{item.address_detail}}</view>
			<view class="flexbetween margin_top">
				<view class="flexleft">
					<view class="morenbtn flexcenter margin_right1" v-show="item.status==1">默认</view>
					<view class="ershil xiaohui">{{item.name}} {{item.mobile}}</view>
				</view>
				<view class="flexright"  @click.stop="tzxzshdz(item.id)">
					<image style="width: 26rpx;height: 26rpx;" src="../static/image/system/bj.png" mode=""></image>
				</view>
			</view>
		</view>
		<!--  -->
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="jumpurl('/pages_mypage/xinzengshdz')">+新增收货地址</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: 0,
				addressList: [],
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
			}
		},
		onShow() {
			this.getAddressList()
		},
		methods: {
			checkaddress(id){
				if(this.type==1){
					uni.$emit("checkAddressId",id)
					uni.navigateBack(1)
				}
			},
			// 设置默认地址
			selectmr(item) {
				if (item.status == 1) {
					return false
				}
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				httpRequest.request('/api/user/setAddressMr', 'GET', {
					id: item.id,
					status: item.status == 0 ? 1 : 0,
				}, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						this.getAddressList()
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			editAddress(id) { //编辑收货地址
				uni.navigateTo({
					url: "/pages_homepage/xinzenshdz?id=" + id
				})
			},
			// 删除地址
			shanchu(id) {
				httpRequest.modal('提示', '确认删除当前数据吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/deladdress', 'GET', {
							id: id
						}, false, false, true).then(res => {
							if (res.code == 1) {
								httpRequest.toast(res.msg)
								this.getAddressList()
							} else {
								httpRequest.toast(res.msg)
							}
						})
					}
				})
			},
			getAddressList() { //地址列表
				httpRequest.request('/api/user/addressList', 'GET', {}).then(res => {
					if (res.code == 1) {
						console.log(res.data)
						this.addressList = res.data
					}
				})
			},
			// 跳转新增收货地址
			tzxzshdz(id) {
				uni.navigateTo({
					url: '/pages_mypage/xinzengshdz?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.sahngbj {
		margin-top: 30rpx;
	}

	.sahngbj:first-child {
		margin-top: 0rpx;
	}
	.morenbtn{
		width: 60rpx;
		height: 30rpx;
		background: #ffedec;
		border-radius: 37rpx 37rpx 37rpx 37rpx;
		font-weight: 400;
		line-height: 18rpx;
		font-size: 18rpx;
		color: #DB2E2E;
	}
</style>